package com.huawei.zyb.taskManager.domain.requirement.valueobject;

/**
 * 需求状态枚举值对象
 */
public enum RequirementStatus {
    DRAFT("草稿"),
    ACTIVE("活跃"),
    COMPLETED("已完成"),
    CANCELLED("已取消");

    private final String description;

    RequirementStatus(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 检查是否可以从当前状态转换到目标状态
     */
    public boolean canTransitionTo(RequirementStatus targetStatus) {
        if (this == targetStatus) {
            return false;
        }

        return switch (this) {
            case DRAFT -> targetStatus == ACTIVE || targetStatus == CANCELLED;
            case ACTIVE -> targetStatus == COMPLETED || targetStatus == CANCELLED;
            case COMPLETED, CANCELLED -> false; // 终态
        };
    }

    /**
     * 检查是否为终态
     */
    public boolean isFinalState() {
        return this == COMPLETED || this == CANCELLED;
    }

    /**
     * 检查是否可以创建任务
     */
    public boolean canCreateTasks() {
        return this == ACTIVE;
    }
}